#include "MachineCorrect.h"
#include "ui_MachineCorrect.h"
#include "enumfontsome.h"
#include <QMessageBox>
#include <QDebug>


MachineCorrect::MachineCorrect(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MachineCorrect)
{
    ui->setupUi(this);
    this->setWindowTitle("变位机测试");

    max_G = 800;
    max_R = 720;
    max_A = 45;
    min_G = 0;
    min_R = -720;
    min_A = -45;

    ui->pb_gotoA->setText(QChar(IconIdentity::icon_location_arrow));
    ui->pb_gotoG->setText(QChar(IconIdentity::icon_location_arrow));
    ui->pb_gotoR->setText(QChar(IconIdentity::icon_location_arrow));
}

MachineCorrect::~MachineCorrect()
{
    delete ui;
}



//void MachineCorrect::on_pb_relaU_clicked()
//{
////    double len = ui->lel_relaU->text().toDouble(new bool);
////    int speed = ui->les_relaU->text().toInt(new bool);
////    MachineHelper::GetInstance()->_mb_ptr->rotate(GROUNDRAIL,len,speed);
//}

//void MachineCorrect::on_pb_relaA_clicked()
//{
////    double len = ui->lel_relaA->text().toDouble(new bool);
////    int speed = ui->les_relaA->text().toInt(new bool);
////    MachineHelper::GetInstance()->_mb_ptr->rotate(FLIPDISK,len,speed);
//}

//void MachineCorrect::on_pb_relaR_clicked()
//{
////    /* 获取原有角度，加上偏移量 */
////    double len = ui->lel_relaR->text().toDouble(new bool);
////    int speed = ui->les_relaR->text().toInt(new bool);
////    MachineHelper::GetInstance()->_mb_ptr->rotate(ROTATINGDISK,len,speed);
//}

//void MachineCorrect::on_pb_Goto_clicked()
//{
////    MachineArgs arg;
////    arg.u = ui->lel_absU->text().toDouble(new bool);
////    arg.a = ui->lel_absA->text().toDouble(new bool);
////    arg.r = ui->lel_absR->text().toDouble(new bool);
////    arg.Su = ui->les_abs_u->text().toDouble(new bool);
////    arg.Sa = ui->les_abs_A->text().toDouble(new bool);
////    arg.Sr = ui->les_abs_R->text().toDouble(new bool);
////    MachineHelper::GetInstance()->ABSMove(arg);
//}

//void MachineCorrect::on_pb_ASBR_clicked()
//{
////    double len = ui->lel_relaR->text().toDouble(new bool);
////    int speed = ui->les_relaR->text().toInt(new bool);
////    MachineHelper::GetInstance()->_mb_ptr->rotate(ROTATINGDISK,len,speed);
//}

//void MachineCorrect::on_pb_ABSA_clicked()
//{
////    double len = ui->lel_relaA->text().toDouble(new bool);
////    int speed = ui->les_relaA->text().toInt(new bool);
////    MachineHelper::GetInstance()->_mb_ptr->rotate(FLIPDISK,len,speed);
//}

//void MachineCorrect::on_pb_ABSU_clicked()
//{
////    double len = ui->lel_relaU->text().toDouble(new bool);
////    int speed = ui->les_relaU->text().toInt(new bool);
////    MachineHelper::GetInstance()->_mb_ptr->rotate(GROUNDRAIL,len,speed);
//}

//void MachineCorrect::on_pb_default_clicked()
//{

//}

//void MachineCorrect::on_gb_Model_toggled(bool arg1)
//{
//    _isRelative = arg1;
//}

void MachineCorrect::on_pb_gotoG_clicked()
{
    bool ret ;
    auto len = ui->lel_absG->text().toDouble(&ret);
    if(!ret){
        QMessageBox::warning(this, tr("参数错误"),
                                         tr("地轨的数据无法转换!\n"), QMessageBox::Cancel);
        return;
    }
    auto speed = ui->les_abs_G->text().toDouble(&ret);
    if(!ret){
        QMessageBox::warning(this, tr("参数错误"),
                                         tr("地轨的速度无法转换!\n"), QMessageBox::Cancel);
        return;
    }
    auto m = ui->cb_GMM->currentIndex();    // 0.立即转  1.延时转
    auto g = ui->cb_GMS->currentIndex();    // 0.相对运动  1.绝对运动

}

void MachineCorrect::on_pb_gotoR_clicked()
{
    bool ret ;
    auto len = ui->lel_absR->text().toDouble(&ret);
    if(!ret){
        QMessageBox::warning(this, tr("参数错误"),
                                         tr("旋转轴的数据无法转换!\n"), QMessageBox::Cancel);
        return;
    }
    auto speed = ui->les_abs_R->text().toDouble(&ret);
    if(!ret){
        QMessageBox::warning(this, tr("参数错误"),
                                         tr("旋转轴的速度无法转换!\n"), QMessageBox::Cancel);
        return;
    }
    auto m = ui->cb_RMM->currentIndex();    // 0.立即转  1.延时转
    auto g = ui->cb_RMS->currentIndex();    // 0.相对运动  1.绝对运动
}

void MachineCorrect::on_pb_gotoA_clicked()
{
    bool ret ;
    auto len = ui->lel_absA->text().toDouble(&ret);
    if(!ret){
        QMessageBox::warning(this, tr("参数错误"),
                                         tr("翻转轴的数据无法转换!\n"), QMessageBox::Cancel);
        return;
    }
    auto speed = ui->les_abs_A->text().toDouble(&ret);
    if(!ret){
        QMessageBox::warning(this, tr("参数错误"),
                                         tr("翻转轴的速度无法转换!\n"), QMessageBox::Cancel);
        return;
    }
    auto m = ui->cb_AMM->currentIndex();    // 0.立即转  1.延时转
    auto g = ui->cb_AMS->currentIndex();    // 0.相对运动  1.绝对运动
}


void MachineCorrect::on_vs_gL_valueChanged(int value)
{
    double t = (max_G - min_G) * ( value ) / 100.00 ;
    ui->lel_absG->setText(QString::number(t));
}

void MachineCorrect::on_vs_rL_valueChanged(int value)
{
    double t = (max_R - min_R) * ( value - 50) / 100.00 ;
    ui->lel_absR->setText(QString::number(t));
}

void MachineCorrect::on_vs_aL_valueChanged(int value)
{
    double t = (max_A - min_A) * ( value - 50) / 100.00 ;
    ui->lel_absA->setText(QString::number(t));
}
